from openpyxl import load_workbook

from QuickTools import tools_pmc

wb = load_workbook(
    "//192.168.70.101/19计划管理部/01.计划/5，物控管理/8、相机版本变更分析/" + tools_pmc.today_str1 + ".xlsx")
ws1 = wb["品号分析"]
ws2 = wb["版本分析"]

temp = "q"
temp2 = "q"
temp3 = "q"

a = 0  # 未生产即失效品号数量
b = 0  # 未排产即失效版本数量
c = 1  # 版本分析
# 未生产即失效品号数量
for i in range(ws1.max_row, 1, -1):
    if ws1.cell(i, 1).value != temp:
        temp = ws1.cell(i, 1).value
        temp2 = ws1.cell(i, 5).value
        temp3 = ws1.cell(i, 5).value
        ws1.cell(i, 6).value = True
    else:
        if ws1.cell(i, 5).value == temp2:
            temp3 = ws1.cell(i, 5).value
            ws1.cell(i, 6).value = True
        else:
            temp3 = ws1.cell(i, 5).value
            ws1.cell(i, 6).value = False

    if ws1.cell(i, 6).value == False and ws1.cell(i, 3).value == "否":
        a += 1

for i in range(2, ws1.max_row + 1):
    if ws2.cell(c, 1).value != ws1.cell(i, 1).value or \
            ws2.cell(c, 3).value != ws1.cell(i, 5).value:
        c += 1
        ws2.cell(c, 1).value = ws1.cell(i, 1).value
        ws2.cell(c, 2).value = ws1.cell(i, 3).value
        ws2.cell(c, 3).value = ws1.cell(i, 5).value
        ws2.cell(c, 4).value = ws1.cell(i, 6).value
    else:
        if ws1.cell(i, 3).value == "是":
            ws2.cell(c, 2).value = "是"
wb.save("//192.168.70.101/19计划管理部/01.计划/5，物控管理/8、相机版本变更分析/" + tools_pmc.today_str1 + "-1.xlsx")

print(a)
print(b)
